import { Component } from './component';

export const Model = {
    content:new Map(),

    setContent(key,value){
        this.content.set(key,value);
    },
    getContent(){
        return this.content;
    },

    onContent(dom){
        dom.forEach((value,index,arrya)=>{
            value.onclick = ()=>{
                document.querySelectorAll(".content-text")[index].innerText = Model.getContent().get(index).content;
                value.style.display = "none";
            }
        });
    },
    onShowComment(dom){
        dom.forEach((value,index,arrya)=>{
            value.onclick = ()=>{
                if(value.id === ""||value.id === "false"){
                    value.nextElementSibling.innerHTML = Component.CommentBox(Model.getContent().get(index).comment);
                    value.id = "true";
                }else{
                    value.nextElementSibling.innerHTML = "";
                    value.id = "false";
                }
            }
        });
    }
};